package com.ftg.learn.springbootmq.topic.service;

import com.ftg.learn.springbootmq.topic.entity.User;
import com.ftg.learn.springbootmq.topic.producer.TopicProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private TopicProducer topicProducer;

    public void registerUser(User user) {
        // 业务逻辑处理
        user.setUserId("USER_" + System.currentTimeMillis());

        // 发送消息到用户队列
        topicProducer.sendUserMessage("register", user);
    }

    public void loginUser(String username) {
        // 业务逻辑处理

        // 发送消息到用户队列
        topicProducer.sendUserMessage("login", username);
    }

    public void updateUser(User user) {
        // 业务逻辑处理

        // 发送消息到用户队列
        topicProducer.sendUserMessage("update", user);
    }
}
